package per.qiao;

import com.intellij.openapi.editor.colors.EditorColorsManager;
import com.intellij.openapi.editor.colors.TextAttributesKey;
import com.intellij.openapi.editor.markup.EffectType;
import com.intellij.openapi.editor.markup.TextAttributes;
import com.intellij.ui.JBColor;
import org.jetbrains.annotations.NotNull;

import java.awt.*;
import java.util.List;

/**
 * 用来配置 文本颜色的类
 */
public class TextAttributesFactory {

    private static final TextAttributesFactory INSTANCE = new TextAttributesFactory();

    private static int INDEX;

    public static TextAttributesFactory getInstance() {
        return INSTANCE;
    }

    //private List<NamedTextAttr> namedTextAttrs;

    public TextAttributesFactory() {
        update();
    }

    public void update() {
        //namedTextAttrs = MultiHighlightConfig.getInstance().getNamedTextAttrs();
    }

    @NotNull
    public NamedTextAttr get() {

        //final List<NamedTextAttr> colors = this.namedTextAttrs;

        // 这里自定义一个灰色前景，idea默认背景作为背景得颜色
        TextAttributesKey REFERENCE_HYPERLINK_COLOR = TextAttributesKey.createTextAttributesKey("grey", new TextAttributes(JBColor.GRAY, (Color)null, JBColor.background(), EffectType.BOXED, 0));
        NamedTextAttr IDE_DEFAULT = new NamedTextAttr("grey",
                EditorColorsManager.getInstance()
                        .getGlobalScheme()
                        .getAttributes(REFERENCE_HYPERLINK_COLOR));
        return IDE_DEFAULT;

        // 这里部分根据是否配置了MultiHiginlight.xml ，使用轮询的方式变换颜色
        /*if (colors.isEmpty()) {
            return IDE_DEFAULT; //NamedTextAttr.IDE_DEFAULT; // NOTICE: remember me
        } else {
//            return colors.get(INDEX++ % colors.size());
            return colors.get(17);
        }*/
    }
}